package com.mosai.alignpro.entity;

import android.text.TextUtils;

import com.mosai.alignpro.util.DateUtils;
import com.mosai.alignpro.util.Utils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 病人图片信息
 * Created by Rays on 2020/3/19.
 */
public final class ImageInfo implements Serializable {

    public static final int STATUS_FAIL = -1; // AI失败
    public static final int STATUS_NO_DATA = 1; // AI未出结果
    public static final int STATUS_PENDING = 2; // 待审核
    public static final int STATUS_AUDITED = 3; // 已审核

    public static final int CONDITION_STATUS_INIT = 0; // 初始
    public static final int CONDITION_STATUS_MILD = 1; // 轻度
    public static final int CONDITION_STATUS_MODERATE = 2; // 中度
    public static final int CONDITION_STATUS_SEVERE = 3; // 重度

    // 1:X光背面 2:X光侧面 3:裸背初筛 4:VR  5:左手X光  6右手X光  7:裸背分析
    public static final int IMAGE_TYPE_BACK_X = 1; // X光背面
    public static final int IMAGE_TYPE_SIDE_X = 2; // X光侧面
    public static final int IMAGE_TYPE_BACK = 3; // 裸背初筛
    public static final int IMAGE_TYPE_BACK_VR = 4; // VR
    public static final int IMAGE_TYPE_HAND_LEFT = 5; // 左手X光
    public static final int IMAGE_TYPE_HAND_RIGHT = 6; // 右手X光
    public static final int IMAGE_TYPE_BACK_ANALYZE = 7; // 裸背分析

    /**
     * id : 0
     * patientId : 0
     * url : string
     * imageType : 1
     * aiOriginResult : string
     * takeDate : 2020-03-20T01:50:26.927Z
     * status : 1
     * patientInfo : {"doctorId":0,"patientId":0,"remark":"string","status":0,"patientType":1,"source":0,"conditionStatus":1,"medicalHistoryInfo":{"symptom":["string"],"disease":["string"],"habit":["string"],"spineSurgeryInstructions":"string"},"name":"string","avatar":"string","sex":1,"birthday":"string","phoneNumber":"string","email":"string","height":0,"weight":0,"latitude":0,"longitude":0,"distance":0,"country":"string","address":"string","sexTxt":"string","id":0}
     */

    private int id;
    private int imageId;
    private int patientId;
    private String url;
    private int imageType; // 类型 X光背面/X光侧面/裸背
    private String aiOriginResult; // AI原始结果
    private String aiDiagnosisDate; // AI出结果时间
    private String checkResultInfo; // 编辑保存后的AI数据
    private String addCheckResultInfo; // 自定义新增的AI数据
    private String takeDate; // 拍摄日期
    private String auditDate; // 审核时间
    private String handleDate; // 处理时间
    private String creationTime; // 插入时间
    private int status;
    private int conditionStatus; // 病情程度（1：轻度，2中度，3重度）
    private String describe; // 病情程度描述
    private PatientInfo patientInfo;
    private boolean patientIsRead;
    private boolean doctorIsRead;
    private int aiOriginScoliosisType; // 病情类型，imageType为3时
    private int scoliosisType; // 病情类型，imageType为3时
    private int newScoliosisType;
    private String aiOriginSeverity;

    private DoctorInfo doctorInfo;
    private List<ImageInfo> histories;
    private ImageInfo lastOriginResult;

    private boolean editing; // 是否正在编辑
    private String angleText; // TK、LL、SS
    private int newConditionStatus; // 编辑后的病情程度（1：轻度，2中度，3重度）
    private String newDescribe; // 编辑后的病情程度描述
    private String newAngleText; // 新的TK、LL、SS
    private String newAIResult;
    private String newAddCheckResultInfo;
    private List<Angle> angles; // 编辑后的角度信息
    private Point circlePoint; // 编辑后的圆点信息
    private Date creationDate;
    private boolean history;
    private String historyCreationTime;
    private boolean notEditDescribe; // 未编辑病情程度描述

    public int getConditionStatus() {
        return conditionStatus;
    }

    public void setConditionStatus(int conditionStatus) {
        this.conditionStatus = conditionStatus;
    }

    public boolean isEditing() {
        return editing;
    }

    public void setEditing(boolean editing) {
        this.editing = editing;
    }

    public String getAngleText() {
        return angleText;
    }

    public void setAngleText(String angleText) {
        this.angleText = angleText;
    }

    public DoctorInfo getDoctorInfo() {
        return doctorInfo;
    }

    public void setDoctorInfo(DoctorInfo doctorInfo) {
        this.doctorInfo = doctorInfo;
    }

    public List<ImageInfo> getHistories() {
        return histories;
    }

    public void setHistories(List<ImageInfo> histories) {
        this.histories = histories;
    }

    public ImageInfo getLastOriginResult() {
        return lastOriginResult;
    }

    public void setLastOriginResult(ImageInfo lastOriginResult) {
        this.lastOriginResult = lastOriginResult;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
        if (imageId == 0) {
            imageId = id;
        }
    }

    public int getImageId() {
        return imageId;
    }

    public void setImageId(int imageId) {
        this.imageId = imageId;
    }

    public int getPatientId() {
        return patientId;
    }

    public void setPatientId(int patientId) {
        this.patientId = patientId;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getImageType() {
        return imageType;
    }

    public void setImageType(int imageType) {
        this.imageType = imageType;
    }

    public String getAiOriginResult() {
        return aiOriginResult;
    }

    public void setAiOriginResult(String aiOriginResult) {
        this.aiOriginResult = aiOriginResult;
    }

    public String getAiDiagnosisDate() {
        return aiDiagnosisDate;
    }

    public void setAiDiagnosisDate(String aiDiagnosisDate) {
        this.aiDiagnosisDate = aiDiagnosisDate;
    }

    public String getCheckResultInfo() {
        if (TextUtils.isEmpty(checkResultInfo)) {
            checkResultInfo = aiOriginResult;
        }
        return checkResultInfo;
    }

    public void setCheckResultInfo(String checkResultInfo) {
        this.checkResultInfo = checkResultInfo;
    }

    public String getAddCheckResultInfo() {
        return addCheckResultInfo;
    }

    public void setAddCheckResultInfo(String addCheckResultInfo) {
        this.addCheckResultInfo = addCheckResultInfo;
    }

    public String getTakeDate() {
        return takeDate;
    }

    public void setTakeDate(String takeDate) {
        this.takeDate = takeDate;
    }

    public String getAuditDate() {
        return auditDate;
    }

    public void setAuditDate(String auditDate) {
        this.auditDate = auditDate;
    }

    public String getHandleDate() {
        return handleDate;
    }

    public void setHandleDate(String handleDate) {
        this.handleDate = handleDate;
    }

    public String getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(String creationTime) {
        this.creationTime = creationTime;
        creationDate = DateUtils.parseUTC(creationTime);
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    public PatientInfo getPatientInfo() {
        return patientInfo;
    }

    public void setPatientInfo(PatientInfo patientInfo) {
        this.patientInfo = patientInfo;
    }

    public boolean isPatientIsRead() {
        return patientIsRead;
    }

    public void setPatientIsRead(boolean patientIsRead) {
        this.patientIsRead = patientIsRead;
    }

    public boolean isDoctorIsRead() {
        return doctorIsRead;
    }

    public void setDoctorIsRead(boolean doctorIsRead) {
        this.doctorIsRead = doctorIsRead;
    }

    public int getNewConditionStatus() {
        return newConditionStatus;
    }

    public void setNewConditionStatus(int newConditionStatus) {
        this.newConditionStatus = newConditionStatus;
    }

    public String getNewDescribe() {
        return newDescribe;
    }

    public void setNewDescribe(String newDescribe) {
        this.newDescribe = newDescribe;
    }

    public String getNewAngleText() {
        return newAngleText;
    }

    public void setNewAngleText(String newAngleText) {
        this.newAngleText = newAngleText;
    }

    public List<Angle> getAngles() {
        return angles;
    }

    public void setAngles(List<Angle> angles) {
        this.angles = angles;
    }

    public Point getCirclePoint() {
        return circlePoint;
    }

    public void setCirclePoint(Point circlePoint) {
        this.circlePoint = circlePoint;
    }

    public String getNewAIResult() {
        return newAIResult;
    }

    public void setNewAIResult(String newAIResult) {
        this.newAIResult = newAIResult;
    }

    public String getNewAddCheckResultInfo() {
        return newAddCheckResultInfo;
    }

    public void setNewAddCheckResultInfo(String newAddCheckResultInfo) {
        this.newAddCheckResultInfo = newAddCheckResultInfo;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public boolean isHistory() {
        return history;
    }

    public void setHistory(boolean history) {
        this.history = history;
    }

    public String getHistoryCreationTime() {
        return historyCreationTime;
    }

    public void setHistoryCreationTime(String historyCreationTime) {
        this.historyCreationTime = historyCreationTime;
    }

    public boolean isNotEditDescribe() {
        return notEditDescribe;
    }

    public void setNotEditDescribe(boolean notEditDescribe) {
        this.notEditDescribe = notEditDescribe;
    }

    public int getAiOriginScoliosisType() {
        return aiOriginScoliosisType;
    }

    public void setAiOriginScoliosisType(int aiOriginScoliosisType) {
        this.aiOriginScoliosisType = aiOriginScoliosisType;
    }

    public int getScoliosisType() {
        return scoliosisType;
    }

    public void setScoliosisType(int scoliosisType) {
        this.scoliosisType = scoliosisType;
    }

    public int getNewScoliosisType() {
        return newScoliosisType;
    }

    public void setNewScoliosisType(int newScoliosisType) {
        this.newScoliosisType = newScoliosisType;
    }

    public String getAiOriginSeverity() {
        return aiOriginSeverity;
    }

    public void setAiOriginSeverity(String aiOriginSeverity) {
        this.aiOriginSeverity = aiOriginSeverity;
    }

    public boolean isAudited() {
        return status == STATUS_AUDITED;
    }

    public boolean isShowCondition() {
        return imageType == IMAGE_TYPE_BACK_X || imageType == IMAGE_TYPE_BACK;
    }

    public void cancelEdit() {
        editing = false;
        resetEditStatus();
    }

    public void resetEditStatus() {
        newScoliosisType = scoliosisType;
        newConditionStatus = conditionStatus;
        newDescribe = describe;
        newAngleText = angleText;
        notEditDescribe = false;
        angles = null;
        circlePoint = null;
        newAIResult = null;
        newAddCheckResultInfo = null;
    }

    public void init() {
        if (lastOriginResult != null) {
            setDescribe(lastOriginResult.getDescribe());
            if (conditionStatus <= 0) {
                if (lastOriginResult.getConditionStatus() > 0) {
                    setConditionStatus(lastOriginResult.getConditionStatus());
                } else if (!TextUtils.isEmpty(aiOriginSeverity)) {
                    setConditionStatus(Utils.severityToConditionStatus(aiOriginSeverity));
                }
            }
            setScoliosisType(lastOriginResult.getScoliosisType());
            setCheckResultInfo(lastOriginResult.getCheckResultInfo());
            setAddCheckResultInfo(lastOriginResult.getAddCheckResultInfo());
            setHistoryCreationTime(DateUtils.formatAuditDate(lastOriginResult.getCreationTime()));
            if (lastOriginResult.getDoctorInfo() != null) {
                setDoctorInfo(lastOriginResult.getDoctorInfo());
            }
        } else {
            scoliosisType = Math.max(aiOriginScoliosisType, scoliosisType);
            if (conditionStatus <= 0 && !TextUtils.isEmpty(aiOriginSeverity)) {
                setConditionStatus(Utils.severityToConditionStatus(aiOriginSeverity));
            }
        }
        resetEditStatus();
    }
}
